class RoomsController < ApplicationController
  def index
    @current_user = current_user
    redirect_to root_path unless @current_user
    @sender_rooms = Room.where(sender_id: current_user.id)
    @receiver_rooms = Room.where(receiver_id: current_user.id)
    @users = User.all_except(@current_user)
    # @rooms = Room.public_rooms
    # @users = User.all_except(@current_user)
  end
  def create 
    @room = Room.find_or_create_by!(sender_id: current_user.id, receiver_id: params["receiver_id"])
    redirect_to @room
  end
  def show
    @single_room = Room.find(params[:id])
    @current_user = current_user
    redirect_to root_path unless @single_room.sender == current_user or @single_room.receiver == current_user
    @message = Message.new
    @messages = @single_room.messages

  end
end
